package com.lagou.task;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class Test03 {

    public static void main(String[] args) {
        //HashMap 集合，统计字符串"123,456,789,123,456"中每个数字字符串出现的次数并打印出来
        String str = "123,456,789,123,456";
        String[] array = str.split(",");

        Map<String, Integer> map = new HashMap<>();
        for (String tmp : array) {
            if (map.containsKey(tmp)) {
                Integer value = map.get(tmp);
                map.put(tmp, ++value);
            } else {
                map.put(tmp, 1);
            }
        }

        Set<String> keys = map.keySet();
        for (String key : keys) {
            System.out.println(key + "出现了" + map.get(key) + "次");
        }
    }
}
